import request from '@/utils/request'

export function getRoles(data) {
    return request({
        url: '/roles',
        method: 'get',
        params: data
    })
}

export function createRoles(data) {
    return request({
        url: '/roles',
        method: 'post',
        data
    })
}

export function updateRole({id, ...data}) {
    return request({
        url:  `/roles/${id}`,
        method: 'put',
        data
    })
}

export function getRole({id}) {
    return request({
        url: `/roles/${id}`,
        method: 'get'
    })
}

export function deleteRole({id}) {
    return request({
        url: `/roles/${id}`,
        method: "delete"
    })
}

export function copyRole({id, ...data}) {
    return request({
        url: `/roles/${id}`,
        method: "post",
        data
    })
}

export function getMenu({ids}) {
    let url = "";
    ids.forEach(id => {
        url = url + url ? `&roleIds=${id}` : `?roleIds=${id}`
    })
    return request({
        url: `/roles/menu/${url}`,
        method: 'get'
    })
}

export function setMenu(id, menu) {
    return request({
        url: `/roles/menu/${id}`,
        method: 'post',
        data: menu
    })
}

export function getAllOperationPermissions() {
    return request({
        url: '/roles/operations',
        method: 'get'
    })
}

export function getPermission({ids}) {
    let url = "";
    ids.forEach(id => {
        url = url + url ? `&roleIds=${id}` : `?roleIds=${id}`
    })
    return request({
        url: `/roles/permission/${url}`,
        method: 'get'
    })
}

export function getOperation({ids}) {
    let url = "";
    ids.forEach(id => {
        url = url + url ? `&roleIds=${id}` : `?roleIds=${id}`
    })
    return request({
        url: `/roles/operation/${url}`,
        method: 'get'
    })
}

export function setOperation(id, operation) {
    return request({
        url: `/roles/operation/${id}`,
        method: 'post',
        data: operation
    })
}